// import Vue from 'vue'

class Axios {
	constructor() {
		this.options = {
			url: "",
			data: {},
			header: {},
			method: '',
		}
        this.baseUrl = 'http://www/123.com'
	}

	request(url, method, data, otherParams) {
		return new Promise((resolve, reject) => {
			let header = {
				token: getApp().globalData.token
			}
			uni.request({
				url:this.baseUrl +url,
				data,
				method,
				header,
				...otherParams,
				success: (res) => {
					resolve(res)
				},
				fail: (e) => {
					reject(e)
				}
			})
		})
	}

	get(url, params, otherParams = {}) {
		return this.request(url, 'GET', params, otherParams)
	}

	post(url, params, otherParams = {}) {
		return this.request(url, 'POST', params, otherParams)
	}
    put(url, params, otherParams = {}) {
        return this.request(url, 'PUT', params, otherParams)
    }
    delete(url, params, otherParams = {}) {
        return this.request(url, 'DELETE', params, otherParams)
    }
}

let instance = new Axios()

export default instance
